package com.wcj.sort;

public class 选择排序 {

    public static void main(String[] args) {
        int[] arr = new int[]{23,12,36,451,2,89,78,54};
        selectSort(arr);
        //SelectSort(arr,8);
        for (int i : arr) {
            System.out.println(i);
        }


    }

    public static void selectSort(int[] arr){
        for (int i = 0; i < arr.length - 1; i++){
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++){
                if (arr[minIndex] > arr[j]){
                    minIndex = j;
                }
            }
            if (minIndex != i){
                int tmp = arr[i];
                arr[i] = arr[minIndex];
                arr[minIndex] = tmp;
            }
        }
    }


}
